﻿
@inject IPluginFinder pluginFinder
@inject IPermissionService permissionService
@using Urs.Services.Security;
@using Urs.Framework.Menu;
@using Urs.Services.Plugins;
@{

    //load sitemap
    var siteMap = new Urs.Framework.Menu.XmlSiteMap();
    siteMap.LoadFrom("~/Areas/Admin/sitemap.config");

}
<!-- 侧边菜单 -->
<div class="layui-side layui-side-menu">
    <div class="layui-side-scroll">
        <div class="layui-logo" lay-href="@Url.Action("Console","Home")">
            <span>UrShop管理系统</span>
        </div>
        <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
            @{
                //standard (default) items
                var rootNode = siteMap.RootNode;

                //plugins
                var adminMenuPlugins = pluginFinder.GetPlugins<IAdminMenuPlugin>().ToList();
                foreach (var adminMenuPlugin in adminMenuPlugins)
                {
                    adminMenuPlugin.ManageSiteMap(rootNode);
                }
                //"Plugins" menu item should be visible when it has some child nodes
                var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
                if (pluginNode != null && pluginNode.Visible)
                {
                    var hasManagePluginsPermission = permissionService.Authorize(StandardPermissionProvider.ManagePlugins);
                    pluginNode.Visible = hasManagePluginsPermission && pluginNode.ChildNodes.Any(x => x.Visible);
                }
            }
            @foreach (var item in siteMap.RootNode.ChildNodes.Where(x => x.Visible))
            {
                @await Html.PartialAsync("_MenuItem", item)
            }
        </ul>
    </div>
</div>
